﻿Imports System.Net.NetworkInformation

Public Class InternetChecks


    Public Shared Function NetworkStateChange(ByVal sender As Object, ByVal e As NetworkAvailabilityEventArgs) As Boolean
        Try

            If e.IsAvailable And CheckInternetSvr() Then
                InternetBack()
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        Return True
    End Function

    Public Shared Function ServerDown() As Boolean
        Return True
    End Function

    Public Shared Function NoInternet() As Boolean
        Return True
    End Function

    Public Shared Function InternetBack() As Boolean
        MySQLManager.Connect()
        Return True
    End Function

    Public Shared Function CheckInternetSvr() As Boolean
        'Change with our server name ;), but keep google as a point of reference
        MainWindow.ConnectImage.Image = My.Resources.world
        Try
            My.Computer.Network.Ping("google.com")
            My.Computer.Network.Ping("bing.com")
        Catch ex As Exception
            MySQLManager.InternetConnection = False
            MainWindow.ConnectImage.Image = My.Resources.world_delete
            InternetChecks.NoInternet()
            Return False
        End Try

        Try
            If MySQLManager.InternetConnection Then
                My.Computer.Network.Ping("google.com")
            End If
        Catch ex As Exception
            MySQLManager.ServerDown = True
            MainWindow.ConnectImage.Image = My.Resources.world_delete
            InternetChecks.ServerDown()
            Return False
        End Try
        Return True
    End Function

End Class
